package com.feri.cloudlike.provider.dto;

import com.feri.cloudlike.common.dto.ContentLikeDto;
import com.feri.cloudlike.common.dto.LikeAddDto;
import com.feri.cloudlike.entity.Like;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * projectName: Cloudlike
 * author: CGY
 * time: 2020/10/30 17:12
 * description:
 */
public interface LikeDao {
    //新增
    @Insert("insert into t_like(uid,cid,ctime) values(#{uid},#{cid},now())")
    int insert(LikeAddDto dto);
    //删除
    @Delete("delete from t_like where uid=#{uid} and cid=#{cid}")
    int del(LikeAddDto dto);
    //查询 某个内容的点赞记录
    @Select("select * from t_like where cid=#{cid} order by ctime desc")
    @ResultType(Like.class)
    List<Like> queryByCid(int cid);
    //查询是否点赞
    @ResultType(Like.class)
    @Select("select * from t_like where uid=#{uid} and cid=#{cid} limit 1")
    Like querySingle(LikeAddDto dto);
    //查询点赞的数量
    @Select("select count(*)ct,cid from t_like group by cid")
    @ResultType(ContentLikeDto.class)
    List<ContentLikeDto> queryCount();
}
